package com.example.kingdee.kingdeeBridge.common;

import com.example.kingdee.sqlTool.sqltoolEnum.FormIdEnum;

import java.util.*;

public class BillObject extends BxMap{

    public BillObject() {
    }

    public BillObject(FormIdEnum formIdEnum) {
        String formId = FormIdEnum.getDBTableName(formIdEnum.name());
        setFormId(formId);
    }

    /**
     * 指定业务对象表单Id
     * @param formId
     */
    public void setFormId(String formId){
        put("formid",formId);
    }

    /**
     *添加表单数据包
     * @param key
     * @param value
     */
    public void setAttribute(String key,Object value){
        Map<String,Object> data = Optional.ofNullable((HashMap<String,Object>)get("Model")).orElse(new LinkedHashMap<>());
        data.put(key,value);
        setData(data);
    }

    /**
     *给当前对象填入键为Model的值
     */
    public void setData(Map<String,Object> data) {
        put("Model",data);
    }


    /**
     * 指定要修改的字段
     */
    public void addNeedUpDateFields(String... needUpDateFields){
        ArrayList<String> needUpDateFieldList = Optional.ofNullable((ArrayList<String>)get("NeedUpDateFields")).orElse(new ArrayList<>());
        needUpDateFieldList.addAll(Arrays.asList(needUpDateFields));
        setNeedUpDateFields(needUpDateFieldList);
    }

    /**
     *给当前对象填入键为NeedUpDateFields的值
     */
    public void setNeedUpDateFields(ArrayList<String> needUpDateFields){
        put("NeedUpDateFields",needUpDateFields);
    }

    /**
     * 单据编码集合，数组类型，格式：[No1,No2,...]（使用编码时必录）
     */
    public void addNumbers(String... numbers){
        ArrayList<String> numberList = Optional.ofNullable((ArrayList<String>)get("Numbers")).orElse(new ArrayList<>());
        numberList.addAll(Arrays.asList(numbers));
        setNumbers(numberList);
    }

    /**
     *给当前对象填入键为Numbers的值
     */
    public void setNumbers(ArrayList<String> numberList){
        put("Numbers",numberList);
    }
}
